home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / workbench / blankery / blanker / source / blankers / puzzle / blank.c next >
C/C++ Source or Header  |  1993-08-15  |  3KB  |  114 lines

  1. #include <exec/types.h>
  2. #include <exec/memory.h>
  3.  
  4. #include <intuition/intuition.h>
  5. #include <intuition/screens.h>
  6.  
  7. #include <graphics/gfx.h>
  8. #include <dos/dos.h>
  9.  
  10. #include <clib/exec_protos.h>
  11. #include <clib/dos_protos.h>
  12. #include <clib/intuition_protos.h>
  13. #include <clib/graphics_protos.h>
  14. #include <clib/alib_protos.h>
  15.  
  16. #include "Puzzle.h"
  17. #include "/defs.h"
  18. #include "/utility.h"
  19.  
  20. struct pPrefObject {
  21.     ULONG Horiz, Vert;
  22. };
  23.  
  24. extern    struct    pPrefObject    nP;
  25. extern        ULONG    Mode, Depth;
  26. extern        UBYTE    *prefData;
  27.  
  28. #define UP    0
  29. #define DOWN    1
  30. #define LEFT    2
  31. #define RIGHT    3
  32.  
  33. WORD getNewDir( WORD x, WORD y, WORD xmax, WORD ymax, WORD olddir )
  34. {
  35.     WORD dir, a1[] = { UP, DOWN, LEFT, RIGHT }, a2[] = { DOWN, UP, RIGHT, LEFT };
  36.  
  37.     dir = RangeRand(4 );
  38.     if( !x && dir == RIGHT ) dir = LEFT;
  39.     if( !y && dir == DOWN ) dir = UP;
  40.     if( x > xmax && dir == LEFT ) dir = RIGHT;
  41.     if( y > ymax && dir == UP ) dir = DOWN;
  42.     while( a1[dir] == a2[olddir] ) {
  43.         dir = RangeRand( 4 );
  44.         if( !x && dir == RIGHT ) dir = LEFT;
  45.         if( !y && dir == DOWN ) dir = UP;
  46.         if( x > xmax && dir == LEFT ) dir = RIGHT;
  47.         if( y > ymax && dir == UP ) dir = DOWN;
  48.     }
  49.     return( dir );
  50. }
  51.  
  52. VOID blank( VOID )
  53. {
  54.     struct    pPrefObject    *pP;
  55.     struct    Screen        *PScr;
  56.     struct    RastPort    *Rast;
  57.         Point        c = { 0, 0 }, n = { 0, 0 };
  58.         WORD        i, dir = UP, xmax, ymax, wid, hei;
  59.  
  60.     if( PuzzleWnd ) pP = &nP;
  61.     else pP = ( struct pPrefObject * )prefData;
  62.  
  63.     if( PScr = cloneTopScreen() ) {
  64.  
  65.         Rast = &( PScr->RastPort );
  66.         wid = PScr->Width / pP->Horiz;
  67.         hei = PScr->Height / pP->Vert;
  68.  
  69.         SetAPen( Rast, 2 );
  70.         for( i = 0; i < PScr->Width; i += wid ) {
  71.             Move( Rast, i, 0 );
  72.             Draw( Rast, i, PScr->Height-1 );
  73.         }
  74.         for( i = 0; i < PScr->Height; i += hei ) {
  75.             Move( Rast, 0, i );
  76.             Draw( Rast, PScr->Width-1, i );
  77.         }
  78.  
  79.         SetAPen( Rast, 1 );
  80.         for( i = wid-1; i < PScr->Width; i += wid ) {
  81.             Move( Rast, i, 0 );
  82.             Draw( Rast, i, PScr->Height-1 );
  83.         }
  84.         for( i = hei-1; i < PScr->Height; i += hei ) {
  85.             Move( Rast, 0, i );
  86.             Draw( Rast, PScr->Width-1, i );
  87.         }
  88.  
  89.         xmax = PScr->Width - 2*wid;
  90.         ymax = PScr->Height - 2*hei;
  91.  
  92.         SetAPen( Rast, 3 );
  93.  
  94.         BlankMousePointer();
  95.  
  96.         while(!( SetSignal( 0L, 0L ) & SIGBREAKF_CTRL_C )) {
  97.             switch( dir = getNewDir( c.x, c.y, xmax, ymax, dir )) {
  98.             case UP: n.y += hei; break;
  99.             case DOWN: n.y -= hei; break;
  100.             case LEFT: n.x += wid; break;
  101.             case RIGHT: n.x -= wid; break;
  102.             }
  103.             BltBitMap( Rast->BitMap, n.x+1, n.y+1, Rast->BitMap, c.x+1, c.y+1, wid-2, hei-2, 0xC0, 0xFF, NULL );
  104.             RectFill( Rast, n.x+1, n.y+1, n.x + wid - 2, n.y + hei - 2 );
  105.             c = n;
  106.             WaitTOF();
  107.         }
  108.         SetSignal( 0L, SIGBREAKF_CTRL_C );
  109.  
  110.         UnblankMousePointer();
  111.         closeTopScreen( PScr );
  112.     }
  113. }
  114.